package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.pojo.CheckItem;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CheckItemMapper {
    /**
     * 添加检查项
     * @param checkItem
     */
    @Insert("insert into t_checkitem (code,name,sex,age,price,type,remark,attention) " +
            "values (#{code},#{name},#{sex},#{age},#{price},#{type},#{remark},#{attention})")
    void add(CheckItem checkItem);

    /**
     * 根据id删除检查项
     * @param id
     */
    @Delete("delete from t_checkitem where id = #{id}")
    void deleteById(Integer id);

    /**
     * 根据id查询检查项
     * @param id
     * @return
     */
    @Select("select * from t_checkitem where id = #{id}")
    CheckItem getById(Integer id);

    /**
     * 编辑检查项
     * @param checkItem
     */
    void update(CheckItem checkItem);

    /**
     * 分页查询
     * @param queryPageBean
     * @return
     */
    Page<CheckItem> pageQuery(QueryPageBean queryPageBean);

    @Select("select * from t_checkitem")
    List<CheckItem> getAll();

    /**
     * 根据检查组id查询检查项id
     * @param checkGroupId
     * @return
     */
    @Select("select checkitem_id from t_checkgroup_checkitem where checkgroup_id = #{id}")
    List<Integer> findChechItemIdByCheckGroupId(Integer checkGroupId);

    /**
     * 根据检查项id查询检查项是否被检查组关联
     * @param id
     * @return
     */
    @Select("select count(checkitem_id) from t_checkgroup_checkitem where checkitem_id = #{id}")
    long findCountByCheckItemId(Integer id);
}
